package com.minyon_web_admin.controller.menu;

import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import net.sf.json.JSONObject;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.minyon_utils.StringUtil;
import com.minyon_web_admin.common.base.BaseController;
import com.minyon_web_admin.common.bean.AjaxResponseBean;
import com.minyon_web_admin.common.bean.DataTablesBean;
import com.minyon_web_admin.model.SysMenuBean;
import com.minyon_web_admin.server.ISysMenu;
import com.minyon_web_admin.shiro.bean.LoginUser;

/**
 * 
 * <br>
 * <b>功能：</b>SysMenuController<br>
 * <br>
 * 
 * @author wwy
 */
@Controller
@RequestMapping("/sys/sysmenu")
public class SysMenuController extends BaseController {

	@Autowired(required = false)
	private ISysMenu sysMenuService;

	/**
	 * 列表页.
	 * 
	 * @return ModelAndView
	 */
	// @RequiresPermissions(PermissionCode.BMS_CRDRECORD_LIST)
	@RequestMapping(value = "/list.shtml", method = RequestMethod.GET)
	public String list(Model model) {
		return "sysMenu/list";

	}

	/**
	 * 查询分页菜单列表.
	 * 
	 * @return
	 * @param reqMap
	 * @return DataTablesBean
	 */
	@RequestMapping("/ajaxGetListPage.shtml")
	@ResponseBody
	public DataTablesBean ajaxGetListPage(@RequestBody Map<String, Object> reqMap) {
		DataTablesBean info = getAjaxDataTablesBeanResultMap(sysMenuService.getListPage(reqMap));
		return info;
	}

	/**
	 * 返回列表页.
	 * 
	 * @param
	 * @return ModelAndView
	 */
	public String goListPage() {
		return "redirect:SysMenu/list";
	}

	/**
	 * 删除数据.
	 * 
	 * @param id
	 * @return ajaxResult
	 */
	@RequestMapping("/ajaxDelete.shtml")
	@ResponseBody
	public AjaxResponseBean ajaxDelete(@RequestBody String id) {
		AjaxResponseBean result = getAjaxResultMap(sysMenuService.deleteInfo(id), false);
		return result;
	}

	/**
	 * 新增数据页面请求.
	 * 
	 * @param id
	 * @return ModelAndView
	 */
	// @RequiresPermissions(PermissionCode.BMS_CRDRECORD_LIST)
	@RequestMapping(value = "/addInfo.shtml", method = RequestMethod.GET)
	public String addInfo(Model model, HttpServletRequest request) {
		return "sysMenu/add";
	}

	/**
	 * ajax新增数据保存.
	 * 
	 * @param id
	 * @return ModelAndView
	 */
	@RequestMapping(value = "/ajaxAddInfo.shtml", method = RequestMethod.POST)
	@ResponseBody
	public AjaxResponseBean ajaxSaveAddInfo(Model model, @RequestBody SysMenuBean bean) {
		AjaxResponseBean result = getAjaxResultMap(sysMenuService.insertInfo(bean), false);
		return result;
	}

	/**
	 * 修改数据页面请求.
	 * 
	 * @param id
	 * @return ModelAndView
	 */
	// @RequiresPermissions(PermissionCode.*)
	@RequestMapping(value = "/updateInfo.shtml", method = RequestMethod.GET)
	public String updateInfo(Model model, String id, HttpServletRequest request) {
		Map<String, Object> reqMap = new HashMap<String, Object>();
		reqMap.put("id", id);
		SysMenuBean bean = getResultMap(sysMenuService.queryDetail(reqMap), false);
		model.addAttribute("updateInfo", bean);
		return "sysMenu/update";
	}

	/**
	 * ajax修改数据.
	 * 
	 * @param id
	 * @return ajaxResult
	 */
	@RequestMapping("/ajaxUpdate.shtml")
	@ResponseBody
	public AjaxResponseBean ajaxUpdate(@RequestBody SysMenuBean bean) {
		AjaxResponseBean result = getAjaxResultMap(sysMenuService.updateInfo(bean), false);
		return result;
	}

	/**
	 * 详细信息请求.
	 * 
	 * @param id
	 * @param model
	 * @return 详情页面
	 */
	@RequestMapping(value = "/detail.shtml", method = RequestMethod.GET)
	// @RequiresPermissions(PermissionCode.BMS_CRDRECORD_LIST)
	public String detail(Model model, Map<String, Object> reqMap) {
		SysMenuBean bean = getResultMap(sysMenuService.queryDetail(reqMap), false);
		model.addAttribute("detailInfo", bean);
		return "sysMenu/detail";
	}
}
